package cn.huxingyuan.service.impl;

import cn.huxingyuan.articletype.domain.ArticleType;
import cn.huxingyuan.articletype.query.ArticleTypeQuery;
import cn.huxingyuan.mapper.ArticleTypeMapper;
import cn.huxingyuan.service.IArticleTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author Hu
 * 2025/8/6 16:54
 */
@Service
public class ArticleTypeServiceImpl implements IArticleTypeService {
    @Autowired
    private ArticleTypeMapper articleTypeMapper;
    @Override
    public ArticleType findById(Long id) {
        return articleTypeMapper.findById(id);
    }

    @Override
    public List<ArticleType> findAll() {
        return articleTypeMapper.findAll();
    }

    @Override
    public void add(ArticleType articleType) {
        articleType.setCreateTime(new Date());
        articleTypeMapper.add(articleType);
    }

    @Override
    public void update(ArticleType articleType) {
        articleType.setUpdateTime(new Date());
        articleTypeMapper.update(articleType);
    }

    @Override
    public void deleteById(Long id) {
        articleTypeMapper.deleteById(id);
    }

    @Override
    public void batchDelete(List<Long> ids) {
        articleTypeMapper.batchDelete(ids);
    }

    @Override
    public PageInfo<ArticleType> pageAll(ArticleTypeQuery articleTypeQuery) {
        PageHelper.startPage(articleTypeQuery.getPage(), articleTypeQuery.getSize());
        List<ArticleType> pageInfo = articleTypeMapper.pageAll(articleTypeQuery);
        return new PageInfo<>(pageInfo);
    }
}
